package com.haiyi.software.app;

import com.haiyi.software.entity.UserInfo;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

@SuppressLint("ResourceAsColor")
public class RegisterPassword extends Activity {

	Button nextBtn;

	EditText passwordText, passwordAgainText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_register_password);
		initComp();
		nextBtn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				switch (checkPassword()) {
				case 0:
					Toast.makeText(v.getContext(), "请填写登陆密码",
							Toast.LENGTH_SHORT).show();
					break;
				case -1:
					Toast.makeText(v.getContext(), "再次密码不一致",
							Toast.LENGTH_SHORT).show();
					break;
				case 1:
					MainApplication mainApplication = (MainApplication) getApplication();
					UserInfo userInfo = (UserInfo) mainApplication.applicationHashtable
							.get("userReg");
					userInfo.setPwd(passwordText.getText().toString().trim());

					// TODO Auto-generated method stub
					Intent intent = new Intent();
					intent.setClass(RegisterPassword.this, RegisterSex.class);
					startActivity(intent);
					break;
				}

			}

			private int checkPassword() {

				String pwd = passwordText.getText().toString().trim();
				String pwdAgain = passwordAgainText.getText().toString().trim();

				if (pwd == null || pwd.length() <= 0) {
					return 0;
				} else {
					if (pwd.equals(pwdAgain)) {
						return 1;
					} else {
						return -1;
					}
				}
			}
		});

	}

	public void initComp() {

		nextBtn = (Button) findViewById(R.id.nextBtn_pass);

		passwordText = (EditText) this.findViewById(R.id.input_pass_editText);

		passwordAgainText = (EditText) this
				.findViewById(R.id.input_pass_again_editText);
	}

}
